package com.itcast.common.exception.controller;

import com.itcast.common.exception.pojo.CsException;
import com.itcast.common.exception.pojo.ExceptionResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/*
* 异常处理类
* */
//@ControllerAdvice
public class CsExceptionController {

    @ExceptionHandler(value = CsException.class) //会去捕捉CsException这种异常
    @ResponseBody //把返回对象转换json字符串
    public ResponseEntity<ExceptionResult> resolveException(CsException e){
        return ResponseEntity.status(e.getStatus()).body(new ExceptionResult(e));
    }

  /*  @ExceptionHandler(value = Exception.class) //会去捕捉CsException这种异常
    @ResponseBody //把返回对象转换json字符串
    public ResponseEntity<ExceptionResult> resolveException(CsException e){
        return ResponseEntity.status(e.getStatus()).body(new ExceptionResult(e));
    }*/
}
